package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.ConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/config")
public class ConfigController {

    private final ConfigService configService;

    @AnnoLog(value = "配置新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addConfig(@RequestBody Map<String, Object> dataParam) {
        return configService.addConfig(dataParam);
    }

    @AnnoLog(value = "配置修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateConfig(@RequestBody Map<String, Object> dataParam) {
        return configService.updateConfig(dataParam);
    }

    @AnnoLog(value = "配置删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteConfig(@RequestBody Map<String, Object> dataParam) {
        return Result.success(configService.deleteConfig((String) dataParam.get("ids")));
    }

    @AnnoLog(value = "配置列表")
    @PostMapping("/list")
    public Result<?> configList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(configService.getConfigPage(queryParam));
    }

    @AnnoLog(value = "配置公共列表")
    @GetMapping("/publicList")
    public Result<?> configPublicList() {
        return Result.success(configService.getCacheList());
    }

}
